//
//  PublicTableVc.m
//  Courses
//
//  Created by xxx on 15/1/6.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "PublicTableVc.h"
#import "PublicCell.h"

#import "CoursesViewController.h"
#import "PublicDetailsVc.h"
#import "LeTVViewController.h"
#import "PXHGetNetworkStatus.h"
@implementation PublicTableVc

SYNTHESIZE_SINGLETON_FOR_IMPL(PublicTableVc)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PublicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[PublicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    if (self.items.count > indexPath.row)
    {
        cell.course = self.items[indexPath.row];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (NSArray *)fetchedItems
{
    return [PublicCourse publicCoursesWithSortOption:self.sortOption teacherId:self.teacherId tagId:self.tagId pageNo:self.pageNo];
}

-(void)getArray{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       self.items = [[PublicCourse publicCoursesWithSortOption:self.sortOption teacherId:self.teacherId tagId:self.tagId pageNo:self.pageNo] mutableCopy];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
       });
    });
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([PXHGetNetworkStatus isWifi]) {
        LeTVViewController* leTV = [[LeTVViewController alloc] init];
        leTV.user_unique = @"a821022973";
        leTV.video_unique = @"ae05447730";
        [[CoursesViewController sharedInstance].navigationController presentViewController:leTV animated:YES completion:nil];
    }else{
        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在WiFi环境下观看视频！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

@end
